package com.tian.service.impl;

import com.tian.entity.ChargeRecord;
import com.tian.mapper.ChargeRecordMapper;
import com.tian.message.ChargingOrderMessage;
import com.tian.service.ChargingOrderStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * {@code @description:} TODO
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-10-25 15:23
 * {@code @version:} 1.0
 */
@Slf4j
@Service
public class ChargingOrderStatusServiceImpl implements ChargingOrderStatusService {
    @Resource
    private ChargeRecordMapper chargeRecordMapper;

    @Override
    public boolean updateChargingOrderStatus(ChargingOrderMessage chargingOrderMessage) {
        ChargeRecord chargeRecord = chargeRecordMapper.selectByPrimaryKey(chargingOrderMessage.getOrderId());
        if (chargeRecord == null) {
            log.error("订单号{}不存在", chargingOrderMessage.getOrderId());
            return true;
        }
        chargeRecord.setId(chargingOrderMessage.getOrderId());
        chargeRecord.setPayStatus(chargingOrderMessage.getStatus());
        chargeRecord.setPayTime(new Date());
        return chargeRecordMapper.updateByPrimaryKey(chargeRecord) > 0;
    }
}
